package leetcode;

/**
 * Created by Ghost on 2014/9/24 0024.
 */
public class Sqrtx {
    public static int sqrt(int x){
        float val = x;
        float last;
        do{
            last = val;
            val = (val + (x/val))/2;
        }while (Math.abs(val-last)<Float.MIN_VALUE);
        return (int)val;
        //return (int) Math.sqrt(x);
    }
    public static void main(String[] args){
        System.out.println(sqrt(2));
    }
}
